package com.shujia.MapReduce;


import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.net.Socket;

public class Demo8ResourceManager {
    public static void main(String[] args) throws IOException {
        Task task = new Task();
        // 启动Socket 客户端
        Socket socket = new Socket("localhost", 8888);

        // 获取输出流
        OutputStream outputStream = socket.getOutputStream();

        // 将输出流转成Object输出流
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);

        // 直接将Task对象通过Object输出流发送出去
        objectOutputStream.writeObject(task);

        objectOutputStream.flush();

    }


}

/**
 * 实际上MapTask、ReduceTask都是线程对象
 * MapTask实际上包含了：分区、分组、排序、map处理逻辑
 * 如果要将MapTask在网络上进行传输，就需要实现序列化接口
 */

class Task extends Thread implements Serializable {
    @Override
    public void run() {
        for (int i = 0; i < 20; i++) {
            System.out.println(i);
            try {

                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }
    }
}
